<?php
/**
 * Created by PhpStorm.
 * User: yhf
 * Date: 2019-01-22
 * Time: 19:56
 */

namespace app\api\controller\v1;


use app\api\service\UserToken;
use app\api\validate\TokenGet;
use app\lib\exception\ParameterException;
use app\api\service\Token as TokenService;

class Token
{
    /**
     * @url /token/getToken
     * @param
     * code {string} 微信code
     * username {number} 学号10位数字
     */
    public function getToken ($code='') {
         //验证必须传值，非空
        (new TokenGet())->goCheck();

        // return $code;

        $ut = new UserToken($code);
        $token = $ut->get();
        return [
            'token' => $token
        ];
    }

    /**
     * @url /token/verify
     * @param
     * token验证
     */
    public function verifyToken($token='') {
        if (!$token) {
            throw new ParameterException([
                'token不允许为空'
            ]);
        }
        $valid = TokenService::verifyToken($token);

        return [
            'idValid' => $valid
        ];
    }
}